#include "list.h"
#include <iostream>
using namespace std;
extern double Sum;
int main(void)
{
	List st;
	char ch;
	customer po;
	cout << "Please enter A to add a purchase order,V to caculate the turnover,S to show the items,or Q to quit." << endl;
	while (cin >> ch && toupper(ch) != 'Q')
	{
		while (cin.get() != '\n')
			continue;
		if (!isalpha(ch))
		{
			cout << "\a";
			continue;
		}
		switch (ch)
		{
		case'A':
		case 'a':
			cout << "Enter the name of customer:";
			getline(cin, po.name);
			cout << "Enter the payment: ";
			cin >> po.consumption;
			cin.get();
			if (st.isfull())
				cout << "List aleady full" << endl;
			else
				st.add(po);
			break;
		case 'S':
		case 's':
			st.showitem();
			break;
		case 'V':
		case 'v':
			if (st.isempty())
			{
				cout << "List is empty." << endl;
				cout << "Sum =  0"  << endl;
			}
			else
			{
				st.visit(turnover());
				cout <<"Sum = "<< Sum << endl;
			}
		}
		cout << "Please enter A to add a purchase order,V to caculate the turnover,S to show the items,or Q to quit." << endl;
	}
	cout << "Bye!" << endl;
 
	system("pause");
	return 0;
}
